package cn.thoughtworks.school.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.*;

import java.util.Date;
import java.util.Map;

@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SerialApplicationResponse {
  private Long id;
  private String title;
  private String reason;
  private String status;
  private String type;
  private String applicant;
  private String email;
  @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
  private Date createTime;

  public static SerialApplicationResponse build(Map application, Map user) {
    return SerialApplicationResponse.builder()
      .id(Long.parseLong(application.get("id").toString()))
      .title(application.get("title") + "")
      .reason(application.get("reason").toString())
      .type(application.get("type").toString())
      .applicant(user.get("name").toString())
      .email(user.get("email").toString())
      .status(application.get("status").toString())
      .createTime((Date) application.get("createTime"))
      .build();
  }
}
